using System;
using System.Data;
using System.Text;

using Wicresoft.Common;
using Wicresoft.Busi.Entity;

namespace Wicresoft.Busi.BizLogic
{
    /// <summary>
    /// Summary description for BLDic_Vehicle.
    /// </summary>
    public class BLDic_Vehicle
    {
        public BLDic_Vehicle()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public static DataTable GetVehicleType()
        {
            return DataAccess.Select(typeof(Dic_Vehicle), Dic_Vehicle.SQLCOL_PROPERTYTYPE + " = '" + VehiclePropertyType.VEHICLETYPE + "'", Dic_Vehicle.SQLCOL_PROPERTYID);
        }

        public static DataTable GetVehicleStatus()
        {
            return DataAccess.Select(typeof(Dic_Vehicle), Dic_Vehicle.SQLCOL_PROPERTYTYPE + " = '" + VehiclePropertyType.VEHICLESTATUS + "'", Dic_Vehicle.SQLCOL_PROPERTYID);
        }

        public static DataTable GetUseTime()
        {
            return DataAccess.Select(typeof(Dic_Vehicle), Dic_Vehicle.SQLCOL_PROPERTYTYPE + " = '" + VehiclePropertyType.USETIME + "'", Dic_Vehicle.SQLCOL_PROPERTYID);
        }

        public static DataTable GetUseStatus()
        {
            return DataAccess.Select(typeof(Dic_Vehicle), Dic_Vehicle.SQLCOL_PROPERTYTYPE + " = '" + VehiclePropertyType.USESTATUS + "'", Dic_Vehicle.SQLCOL_PROPERTYID);
        }

        public static int GetPropertyID(string Type, string Name)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(Dic_Vehicle.SQLCOL_PROPERTYTYPE + " = '" + Type + "'");
            sb.Append(" AND " + Dic_Vehicle.SQLCOL_PROPERTYNAME + " = '" + Name + "'");

            DataTable dt = DataAccess.Select(typeof(Dic_Vehicle), sb.ToString(), string.Empty);
            if (dt.Rows.Count == 0)
                return -1;
            else
                return int.Parse(dt.Rows[0][Dic_Vehicle.SQLCOL_PROPERTYID].ToString());
        }

        public static string GetPropertyName(string Type, int ID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(Dic_Vehicle.SQLCOL_PROPERTYTYPE + " = '" + Type + "'");
            sb.Append(" AND " + Dic_Vehicle.SQLCOL_PROPERTYID + " = " + ID);

            DataTable dt = DataAccess.Select(typeof(Dic_Vehicle), sb.ToString(), string.Empty);
            if (dt.Rows.Count == 0)
                return string.Empty;
            else
            {
                if (dt.Rows[0][Dic_Vehicle.SQLCOL_PROPERTYDESC].ToString().Equals(string.Empty))
                    return dt.Rows[0][Dic_Vehicle.SQLCOL_PROPERTYNAME].ToString();
                else
                    return dt.Rows[0][Dic_Vehicle.SQLCOL_PROPERTYNAME].ToString() + "(" + dt.Rows[0][Dic_Vehicle.SQLCOL_PROPERTYDESC].ToString() + ")";
            }
        }
    }
}
